Skip to contentSkip to conversation

Application using i2c-imx.c

lm-sensors Javier Zugasti 2 participants 8 messages Dec 8, 2009 – Dec 9, 2009

lore
Share & tools
lore
#0 lore raw

Hi everyone.

I wanted to ask if someone has used the i2c-imx driver functionalities to communicate with a LM sensor. I haven't found a single example in the web and I am very inexperienced with Linux.

If so, could you please let me have a look to the application code so that I can understand how to communicate with my LM73 using the functions from the mentioned driver?

Thanks.

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#1 lore raw

Hi Javier,

Quoted 3 lines · Javier Zugasti

I wanted to ask if someone has used the i2c-imx driver functionalities to communicate with a LM sensor. I haven't found a single example in the web and I am very inexperienced with Linux.

You don't really have to care. Almost all I2C-based hwmon drivers should work on top of any I2C bus driver. Exceptions are very rare (and would suggest broken hardware design.)

Quoted 3 lines

If so, could you please let me have a look to the application code so that I can understand how to communicate with my LM73 using the functions from the mentioned driver?

You don't have to do anything, drivers for this already exist. The lm73 driver isn't upstream yet, but it will be in a few days. For now you can pick the patch from there:

ftp://ftp.kernel.org/pub/linux/kernel/people/jdelvare/linux-2.6/jdelvare-hwmon/hwmon-lm73-new-driver.patch

After patching your kernel tree, simply load the i2c-imx and lm73 drivers. Then either declare the lm73 device as part of your platform data, or instantiate it from user-space using
the /sys/bus/i2c/devices/i2c-<n>/new_device file, where <n> is to be replaced with the relevant i2c-imx's bus number (probably 0, if you have a single I2C bus on your system.) And you should be done.

Signature · 7 lines
Jean Delvare
http://khali.linux-fr.org/wishlist.html

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to Javier Zugasti

Hi people,

Thank you very much for your reply Jean.
I patched the kernel tree with the patch you linked me to and then selected the hwmon and lm73 option in the menuconfig options (together with the i2c of course).

After that I used a cross-compiler to compile the kernel for my board and transferred the images to my board and started my linux there.

I assume the system supports i2c now.
No i2c devices appear in the /dev directory or in /sys/bus/i2c/devices, but the lm73 appears in /sys/bus/i2c/drivers and i2c appears in the file /proc/devices:

cat /proc/devices
Character devices:
...
*89 i2c*
...

So now, how can I write an application in the user space that reads the temperature from the lm73? Do I have to use IOCTL calls or how do I do it?

Thanks again for your help and excuse my ignorance. Regards,
Javier

2009/12/9 Jean Delvare <[email protected]>

Quoted 31 lines

Hi Javier,

Quoted 3 lines · Javier Zugasti

I wanted to ask if someone has used the i2c-imx driver functionalities to communicate with a LM sensor. I haven't found a single example in the web and I am very inexperienced with Linux.

You don't really have to care. Almost all I2C-based hwmon drivers should work on top of any I2C bus driver. Exceptions are very rare (and would suggest broken hardware design.)

Quoted 1 line

If so, could you please let me have a look to the application code so

that I

Quoted 1 line

can understand how to communicate with my LM73 using the functions from

the

Quoted 1 line

mentioned driver?

You don't have to do anything, drivers for this already exist. The lm73 driver isn't upstream yet, but it will be in a few days. For now you can pick the patch from there:

ftp://ftp.kernel.org/pub/linux/kernel/people/jdelvare/linux-2.6/jdelvare-hwmon/hwmon-lm73-new-driver.patch

After patching your kernel tree, simply load the i2c-imx and lm73 drivers. Then either declare the lm73 device as part of your platform data, or instantiate it from user-space using
the /sys/bus/i2c/devices/i2c-<n>/new_device file, where <n> is to be replaced with the relevant i2c-imx's bus number (probably 0, if you have a single I2C bus on your system.) And you should be done.

Quoted 4 lines

--
Jean Delvare
http://khali.linux-fr.org/wishlist.html

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#3 lore raw
In reply to Javier Zugasti

Hi Javier,

What about NOT TOP-POSTING, as I requested once already?

Quoted 10 lines · Javier Zugasti

Thank you very much for your reply Jean.
I patched the kernel tree with the patch you linked me to and then selected the hwmon and lm73 option in the menuconfig options (together with the i2c of course).

After that I used a cross-compiler to compile the kernel for my board and transferred the images to my board and started my linux there.

I assume the system supports i2c now.
No i2c devices appear in the /dev directory or in /sys/bus/i2c/devices

Which kernel are you running? I2C adapters only show
in /sys/bus/i2c/devices since kernel 2.6.32. For older kernels you would look for them in /sys/class/i2c-adapter.

Assuming you run an older kernel, please list the entries under /sys/class/i2c-adapter.

, but

Quoted 8 lines

the lm73 appears in /sys/bus/i2c/drivers and i2c appears in the file /proc/devices:

cat /proc/devices
Character devices:
...
*89 i2c*
...

This means i2c-dev is loaded, but you shouldn't need it, see below.

Quoted 2 lines

So now, how can I write an application in the user space that reads the temperature from the lm73? Do I have to use IOCTL calls or how do I do it?

With the lm73 driver you're using, access to the LM73 chip is done through sysfs, very easily. You would have to go through ioctls on /dev/i2c* nodes only if you did _not_ have a kernel driver for the LM73.

Signature · 7 lines
Jean Delvare
http://khali.linux-fr.org/wishlist.html

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#4 lore raw
In reply to Javier Zugasti

Hi Jean,

2009/12/9 Jean Delvare <[email protected]>

Quoted 18 lines

Hi Javier,

What about NOT TOP-POSTING, as I requested once already?

Quoted 2 lines · Javier Zugasti

Thank you very much for your reply Jean.
I patched the kernel tree with the patch you linked me to and then

selected

Quoted 1 line

the hwmon and lm73 option in the menuconfig options (together with the

i2c

Quoted 7 lines

of course).

After that I used a cross-compiler to compile the kernel for my board and transferred the images to my board and started my linux there.

I assume the system supports i2c now.
No i2c devices appear in the /dev directory or in /sys/bus/i2c/devices

Quoted 8 lines

Which kernel are you running? I2C adapters only show
in /sys/bus/i2c/devices since kernel 2.6.32. For older kernels you would look for them in /sys/class/i2c-adapter.

Assuming you run an older kernel, please list the entries under /sys/class/i2c-adapter.

I am using kernel 2.6.31, and there are no entries under

/sys/class/i2c-adapter:

*# ls /sys/class/i2c-*
/sys/class/i2c-adapter:

/sys/class/i2c-dev:

*

Quoted 14 lines

, but

Quoted 8 lines

the lm73 appears in /sys/bus/i2c/drivers and i2c appears in the file /proc/devices:

cat /proc/devices
Character devices:
...
*89 i2c*
...

This means i2c-dev is loaded, but you shouldn't need it, see below.

Quoted 2 lines

So now, how can I write an application in the user space that reads the temperature from the lm73? Do I have to use IOCTL calls or how do I do

Quoted 8 lines

it?

With the lm73 driver you're using, access to the LM73 chip is done through sysfs, very easily. You would have to go through ioctls on /dev/i2c* nodes only if you did _not_ have a kernel driver for the LM73.

OK. I'm going to go through the usage of sysfs and see how it goes. But I

guess it won't until the i2c-adapter appears, right?

Quoted 4 lines

--
Jean Delvare
http://khali.linux-fr.org/wishlist.html

Thank you,
Javier

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#5 lore raw
In reply to Javier Zugasti

Hi Javier,

Quoted 8 lines · Javier Zugasti

2009/12/9 Jean Delvare <[email protected]>

Quoted 6 lines

With the lm73 driver you're using, access to the LM73 chip is done through sysfs, very easily. You would have to go through ioctls on /dev/i2c* nodes only if you did _not_ have a kernel driver for the LM73.

OK. I'm going to go through the usage of sysfs and see how it goes. But I

guess it won't until the i2c-adapter appears, right?

Correct. You have to figure out why your I2C adapter isn't instantiated. This isn't exactly on-topic on this mailing list...

You claim you'd use i2c-imx, how do you know? Did you actually build that driver? If it is modular, did you load the module? Which machine model are you using? i2c-imx is a platform driver, so the i2c-imx device must be instantiated explicitly by the machine init code.

If you can't figure it out, it might be better to ask on list dedicated to arm or even imx if there's one.

Signature · 7 lines
Jean Delvare
http://khali.linux-fr.org/wishlist.html

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#6 lore raw
In reply to Javier Zugasti

Hi

2009/12/9 Jean Delvare <[email protected]>

Quoted 16 lines

Hi Javier,

Quoted 7 lines · Javier Zugasti

2009/12/9 Jean Delvare <[email protected]>

Quoted 6 lines

With the lm73 driver you're using, access to the LM73 chip is done through sysfs, very easily. You would have to go through ioctls on /dev/i2c* nodes only if you did _not_ have a kernel driver for the LM73.

OK. I'm going to go through the usage of sysfs and see how it goes. But

I

Quoted 1 line

guess it won't until the i2c-adapter appears, right?

Correct. You have to figure out why your I2C adapter isn't instantiated. This isn't exactly on-topic on this mailing list...

Quoted 6 lines

You claim you'd use i2c-imx, how do you know? Did you actually build that driver? If it is modular, did you load the module? Which machine model are you using? i2c-imx is a platform driver, so the i2c-imx device must be instantiated explicitly by the machine init code.

Well, in the I2C support from menuconfig I selected the following options:

<*> I2C support --->
<*> I2C device interface
I2C Hardware Bus Support --->
<*> IMX I2C interface

Should I just select I2C support and then use sysfs as you suggested before? Could this be the reason why my I2C adapter isn't
instantiated?

Quoted 7 lines

If you can't figure it out, it might be better to ask on list dedicated to arm or even imx if there's one.

--
Jean Delvare
http://khali.linux-fr.org/wishlist.html

Thanks,
Javier

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#7 lore raw
In reply to Javier Zugasti
Quoted 6 lines · Javier Zugasti

2009/12/9 Jean Delvare <[email protected]>

Quoted 4 lines

You claim you'd use i2c-imx, how do you know? Did you actually build that driver? If it is modular, did you load the module? Which machine model are you using? i2c-imx is a platform driver, so the i2c-imx device must be instantiated explicitly by the machine init code.

Quoted 8 lines

Well, in the I2C support from menuconfig I selected the following options:

<*> I2C support --->
<*> I2C device interface
I2C Hardware Bus Support --->
<*> IMX I2C interface

Should I just select I2C support and then use sysfs as you suggested before?

No, this suggestion of mine was unrelated.

Quoted 1 line

Could this be the reason why my I2C adapter isn't instantiated?

No. If the driver is properly build in, then I suspect that the device itself is missing. Just check in /sys/devices/platform/ if it's there or not. If not then something's missing in your machine init data.

Signature · 7 lines
Jean Delvare
http://khali.linux-fr.org/wishlist.html

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors